package com.dominator.socket;

import com.dominFramework.core.typewrap.Dto;
import com.dominator.enums.ReqEnums;
import com.dominator.service.ApiMachineService;
import com.dominator.utils.api.ApiMessage;
import com.dominator.utils.api.ApiMessageUtil;
import com.dominator.utils.dao.RedisUtil;
import com.dominator.utils.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SocketService {

    @Autowired
    ApiMachineService apiMachineService;

    private RedisUtil ru = RedisUtil.getRu();



    public ApiMessage onMessageService(Dto dto) throws ApiException {
        ApiMessage msg = new ApiMessage();
        if ("machineLogin".equals(dto.getString("method"))) {
            //机器管理
            msg = machineLogin(dto);

        } else if ("machineLogout".equals(dto.getString("method"))) {
            //机器管理
            msg = machineLogout(dto);

        }else if ("userLogin".equals(dto.getString("method"))) {
            //用户登录

        } else if ("userLogout".equals(dto.getString("method"))) {
            //用户登出

        } else if ("userCreateOrder".equals(dto.getString("method"))) {
            //用户下注

        } else if ("sendToMachineId".equals(dto.getString("method"))) {
            //发送给指定会话id
            msg = sendToMachineId(dto);
        } else {
            throw new ApiException(ReqEnums.SOCKET_METHOD_IS_NOT_EXSIT);
        }
        return msg;
    }


    public ApiMessage machineLogin(Dto dto) throws ApiException {
        return apiMachineService.machineLogin(dto);
    }

    public ApiMessage machineLogout(Dto dto) throws ApiException {
        return apiMachineService.machineLogout(dto);
    }


    public ApiMessage sendToMachineId(Dto dto) throws ApiException {
        return apiMachineService.sendToMachineId(dto);
    }
}
